package cn.xjfme.encrypt.dto;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author liuguoqiang
 *
 */
public enum ReturnCodeEnum {

	C200_							(2000,"SUCESS!"),
	C202_ACCOUNT_SERVER_ERROR		(2020,"帐号服务器查询失败，请过一段时间重试"),
	C202_CANNOT_CREATE_APP_FOLDER	(2021,"不能创建用户目录，请重新获取ACCESS TOKEN"),
	C202_LOGIN_FAIL					(2022,"用户名或密码错误，请重新输入"),
	C202_PWD_ERROR					(2029,"旧密码错误，请重新输入"),
	C202_USER_UNACTIVATED				(2027,"账户状态异常"),
	C202_WRONG_VERIFICATION_CODE		(2023,"请输入正确的验证码"),
	C202_COMMIT_FAIL					(2024,"上传失败，请过一段时间重试"),
	C202_BAD_OPENID					(2025,"不能用此OPENID 注册"),
	C202_DUPLICATE_PHONEE			(2026,"该手机号已注册"),

	C202_USER_INVALID				(2028, "用户已失效，请联系管理员"),
	C400_BAD_PARAMETERS				(4000,"参数不正确"),
	C400_BAD_REQUEST					(4001,"请求URL、参数不对"),
	C400_NO_SUCH_API_IMPLEMENTED		(4002,"无此API"),
	C401_BAD_SIGNATURE				(4013,"签名不正确"),
	C401_REQUEST_EXPIRED				(4014,"请求过期（TIMESTAMP 或者NONCE不正确）"),
	C401_BAD_CONSUMER_KEY			(4015,"没有这个CONSUMER KEY （你确定申请了应用？）"),
	C401_NOT_SUPPORTED_AUTH_MODE		(4016,"你不能使用这种授权模式"),
	C401_AUTHORIZATION_EXPIRED		(4017,"用户的授权过期，请重新获取ACCESS_TOKEN"),
	C401_API_DAILY_LIMIT				(4018,"您今天调用接口次数太多了吧"),
	C401_NO_RIGHT_TO_CALL_THIS_API	(4019,"无权限调用此API"),
	C401_MSG_CODE_ERROR	      (4020,"短信验证码收到限制"),
	C401_ACT_TIME_NO_VALID_NOSTART				(4021,"活动未开始"),
	C401_ACT_TIME_NO_VALID_END				(4022,"活动未开始"),
	C4023_NO_AREA_AUTH				(4023,"无此地区权限"),
	C4023_DEPLOYMENT_PARAM_ERROR				(4024,"启动参数必须指定地区"),
	C400_CODE_ERROR				(4025,"验证码不正确"),




	C401_REUSED_NONCE				(40110,"NONCE被重用了"),
	C401_BAD_VERIFIER				(40111,"VERIFIER错误"),
	C403_FILE_EXIST					(4030,"同名文件（夹）已经存在"),
	C403_FORBIDDEN					(4031,"无权限访问，或者无权限进行此操作"),
	C404_FILE_NOT_EXIST				(4040,"文件夹不存在，父目录不存在"),
	C404_MSG_NOT_FOUND				(4041,"查无此数据"),
	C405_METHOD_NOT_SUPPORT			(4050,"不支持此方法"),
	C406_TOO_MANY_FILES				(4060,"一次操作太多文件"),
	C413_FILE_TOO_LARGE				(4130,"文件大小超过能上传的上限"),
	C500_SERVER_ERROR				(5000,"服务器错误，应该是我们遇到BUG了"),
	C507_OVER_SPACE					(5070,"用户空间已满"),
	C508_OVER_SPACE					(5080,"服务器出差去了，稍等下在访问哦！"),



	C405_LOGIN_FAIL					(405,"图片验证码失效"),
	C405_LOGIN_FAIL_1					(406,"请通过验证码"),


	/**
	 * 中青信用后台错误码
	 */
	INCLUDE_SUBORDINATE_DEPARTMENTS					(6001,"包含下级部门,不允许修改"),
	DEPARTMENT_CONTAINS_USERS					(6002,"部门包含用户,不允许修改"),
	IP_ADDRESS_ILLEGAL					(6003,"ip地址不合法"),
	SELECT_INTERFACE_REQUIRED					(6004,"请选择接口"),


	/**
	 * 企业用户错误码
	 */
	AUTH_BASEINFO_ERROR				(19001,"企业不存在"),
	AUTH_BASEINFO_BANGDING_ERROR				(19002,"该企业已经绑定"),
	AUTH_BASEINFO_DENGLURENZHENG_ERROR				(19003,"请先登录后再认证"),
	AUTH_BASEINFO_QIYEFARENSHENFENZHENG_ERROR				(19004,"企业法人身份证号缺失"),
	AUTH_BASEINFOBANGDING_ERROR				(19005,"绑定企业不存在"),
	AUTH_BAOCUNZHUCEYONGHU_ERROR				(19006,"保存注册用户失败"),
	AUTH_ADDSHOUQUAN_ERROR				(19007,"新增授权失败"),
	AUTH_ADDJINGBANREN_ERROR				(19008,"添加经办人失败"),
	AUTH_YONGHUYIJINGRENZHENG_ERROR				(19009,"该企业已被此用户认证"),
	AUTH_ADDRENZHENGQIYE_ERROR				(19010,"保存认证企业失败"),
	AUTH_SHOUQUANJINXINGZHONG_ERROR				(19011,"授权进行中"),
	AUTH_SHOUQUAN_ERROR				(19012,"查询授权状态异常"),
	AUTH_SHOUQUANJILU_ERROR				(19013,"创建授权记录失败"),
	AUTH_RENZHENGQIYE_ERROR				(19014,"请先认证企业"),
	BANK_ORDER_NONE(7001,"订单不存在"),
	BANK_AGREE_ERROR				(7002,"订单状态发生变化，无法同意放贷"),
	BANK_REJECT_ERROR				(7003,"订单状态发生变化，无法拒绝放贷"),

	;

	private int code;
	private String message;
	@SuppressWarnings("unused")
	private String date;
	private Map<String , Object> data;


	public Map<String, Object> getData() {
		return data;
	}

	public ReturnCodeEnum setData(Map<String, Object> data) {
		this.data = data;
		return this;
	}

	public String getDate() {
		return System.currentTimeMillis()+"";
	}

	public ReturnCodeEnum setDate(String date) {
		this.date = date;
		return this;
	}


	private ReturnCodeEnum(int code , String message ){
		this.code = code;
		this.message = message;
	}

 	public int getCode() {
		return code;
	}



 	public String getMessage() {
		return message;
	}



	public static ReturnCodeEnum getEnumByName(int status) {
		ReturnCodeEnum[] enums = ReturnCodeEnum.values();
		for(ReturnCodeEnum enumtype:enums) {
			if(enumtype.getCode()==status) {
				return enumtype;
			}
		}
		return C400_BAD_REQUEST;
	}

	public String toSimpleString() {
		Map<String , Object> map = new HashMap<>();
		map.put("code", code);
		map.put("message", message);
		map.put("date", getDate());
 		return JSON.toJSONString(map) ;
	}

	public Map<String , Object> toSimpleMap() {
        Map<String , Object> map = new HashMap<>();
        map.put("code", code);
        map.put("message", message);
        map.put("date", getDate());
        map.put("data", this.getData());
        this.setData(null);
        return map ;
    }

	public ReturnCodeEnum add(String key , Object value ) {
        Map<String , Object> data = this.getData()==null ?
        			new HashMap<>():this.getData();
        data.put(key, value);
        this.setData(data);
        return this ;
    }

	public Map<String , Object> add2Map(String key , Object value ) {
        Map<String , Object> map = this.toSimpleMap();
        Map<String , Object> data = new HashMap<>();
        data.put(key, value);
        map.put("data", data);
        return map ;
    }

	public String add2String(String key , Object value) {
        Map<String , Object> map = this.toSimpleMap();
        Map<String , Object> data = new HashMap<>();
        data.put(key, value);
        map.put("data", data);
        return JSON.toJSONString(map) ;
    }

	public static void main(String[] args) {
		System.out.println(ReturnCodeEnum.C200_.toSimpleString());
		System.out.println(ReturnCodeEnum.C200_.getCode());
	}

}
